<br/>
{foreach from=$field_errors item=error key=field_caption}
	{if $error eq 'FILE_NOT_SPECIFIED'}
		<p class="error">'{$field_caption}' [[file not specified]]</p>
	{elseif $error eq 'NOT_SUPPORTED_IMAGE_FORMAT'}
		<p class="error">'{$field_caption}' - [[Image format is not supported]]</p>
	{elseif $error eq 'PICTURES_LIMIT_EXCEEDED'}
		<p class="error">'{$field_caption}' [[limit exceeded]]</p>
	{elseif $error eq 'UPLOAD_ERR_INI_SIZE'}
		<p class="error">[[File size exceeds system limit]]</p>
	{elseif $error eq 'UPLOAD_ERR_FORM_SIZE'}
		<p class="error">[[File size exceeds system limit]]</p>
	{elseif $error eq 'UPLOAD_ERR_PARTIAL'}
		<p class="error">[[There was an error during file upload]]</p>
	{elseif $error eq 'UPLOAD_ERR_NO_FILE'}
		<p class="error">'{$field_caption}' [[file not specified]]</p>
	{/if}
{/foreach}
{if $errors != ''}
	{foreach from=$errors item=error_message key=error}
	
		{if $error eq 'WRONG_PARAMETERS_SPECIFIED'}
		<p class="error">[[Wrong parameters are specified]]</p>
	
		{elseif $error eq 'PARAMETERS_MISSED'}
		<p class="error">[[The key parameters are not specified]]</p>
	
		{elseif $error eq 'NOT_OWNER'}
		<p class="error">[[You are not owner of this listing]]</p>
		{/if}
		
	{/foreach}

{else}
	{if $number_of_picture < $number_of_picture_allowed}
		<form id="uploadForm" method="post" action="{$GLOBALS.site_url}/manage-pictures/" enctype="multipart/form-data" onsubmit="return uploadPicture();">
			<input type="hidden" name="action" value="add" />
			<input type="hidden" id="listing_id" name="listing_sid" value="{$listing.id}" />
			<table>
				<tr>
					<td>[[Caption]]</td>
					<td><input type="text" name="caption" value="" /></td>
				</tr>
				<tr>
					<td>[[Add Picture]]</td>
					<td><input type="file" name="picture" /></td>
				</tr>
				<tr>
		        <td></td>
				<td colspan="2">
	          <br/>
					<input type="submit" value="[[Add Picture]]" class="button"/>
					</td>
				</tr>
			</table>
		</form>
		
	{else}
		[[You've reached the limit of number of pictures allowed by your product]]
	{/if}
	
	<br />
	
	<table cellpadding="5">
		{if $pictures}
		<tr>
			<td>[[Thumbnail]]</td>
			<td>[[Caption]]</td>
			<td colspan="2">[[Actions]]</td>
		</tr>
		{foreach from=$pictures item=picture name=pictures_block}
		
		<tr>
			<td><img src="{$picture.thumbnail_url}" alt="" /></td>
			<td>{$picture.caption|truncate:15|escape:"html"}</td>
            <td><a href="#" onclick="editPicture({$listing.id}, {$picture.id}); return false;" class="edit"><img src="{$GLOBALS.site_url}/templates/_system/main/images/b_edit.gif" border="0" alt="" /></a></td>
            <td><a href="#" onclick="deletePicture({$listing.id}, {$picture.id}); return false;" style="cursor:pointer;"><img src="{$GLOBALS.site_url}/templates/_system/main/images/b_drop.gif" /></a></td>
		</tr>
		{/foreach}
		{/if}
	</table>
{/if}
{literal}
<script>

function uploadPicture() {
	var browser = navigator.appName.toLowerCase();
	var options = {
		target: "#UploadPics",
		url:  $("#uploadForm").attr("action") + "?listing_sid=" + {/literal}{$listing.id}{literal},
		beforeSend: function(data) {
			$("#UploadPics").css({"opacity" : "0.3"});
			$("#loading").show();
		},
		success: function(data) {
			$("#UploadPics").css({"opacity" : "1"});
			if ($.browser.msie) {
				data = data.replace(/(\w+)=([^ ">]+)/g, '$1="$2"');
			}
			$("#UploadPics").html(data);
			$("#loading").hide();
	}
	};
	$("#uploadForm").ajaxSubmit(options);
	return false;
}

</script>
{/literal}